<template>
  <MyDialog
    v-model="isVisible"
    :type="type"
    class="audit-dialog-wrapper"
    width="1200"
    :dialog-title="dialogTitle"
    :need-modal="needModal"
    @closed="closed"
  >
    <my-form ref="ruleForm" v-model="dataForm" label-width="160px" disabled :model="dataForm" :is-grid="false" :items-datas="state.itemsDatas">
    </my-form>
    <template #footer>
      <my-button type="reset" title="关闭" @click="closed" />
    </template>
  </MyDialog>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { getAb05 } from '@/api/yuanshidian/ab05';
const { proxy } = getCurrentInstance();
const props = defineProps(
  {
    dialogTitle: {
      type: String,
      default: '台账详情'
    },
    needModal: {
      type: Boolean,
      default: true
    },
    modelValue: {
      type: Boolean,
      default: false
    },
    currentRow: {
      type: Object,
      default: () => {}
    }
  },
  ['modelValue']
);
const buttonLoading = ref(false);
const ruleForm = ref<ElFormInstance>();
const state = reactive({
  dataForm: {
    id: '',
    aaa027: '',
    dw01: '',
    gr03: '',
    dw02: '',
    gr04: '',
    gr02: '',
    gr10: '',
    gr01: '',
    grzh01: '',
    grzh02: '',
    grzh03: '',
    grzh04: '',
    grzh05: '',
    grzh06: '',
    grzh08: '',
    grzh11: '',
    systime: '',
    grzh16: '',
    grjx01: '',
    grzh17: '',
    grzh18: '',
    grzh19: '',
    grzh21: '',
    grzh22: '',
    grzh23: '',
    grzh24: '',
    grzh25: '',
    grzh26: '',
    grzh27: ''
  },
  itemsDatas: [
    { label: '单位编号', prop: 'dw01', type: 'input' },
    { label: '单位名称', prop: 'dw02', type: 'input' },
    { label: '证件号码', prop: 'gr02', type: 'input' },
    { label: '姓名', prop: 'gr04', type: 'input' },
    { label: '个人账号', prop: 'gr03', type: 'input' },
    { label: '个人编码', prop: 'gr01', type: 'input' },
    { label: '本期单位划拨', prop: 'grzh02', type: 'input' },
    { label: '本期个人缴费', prop: 'grzh01', type: 'input' },
    { label: '历年个人缴费', prop: 'grzh04', type: 'input' },
    { label: '本期单位代缴', prop: 'grzh03', type: 'input' },
    { label: '历年单位代缴', prop: 'grzh06', type: 'input' },
    { label: '历年单位缴费', prop: 'grzh05', type: 'input' },
    { label: '建立账户时间', prop: 'gr10', type: 'input' },
    { label: '缴费总月数', prop: 'grzh08', type: 'input' },
    { label: '历年缴费总月数', prop: 'grzh11', type: 'input' },
    { label: '本年补充额', prop: 'grzh16', type: 'input' },
    { label: '个人储畜额', prop: 'grzh17', type: 'input' },
    { label: '历年补充额', prop: 'grzh18', type: 'input' },
    { label: '历年个人储畜额', prop: 'grzh19', type: 'input' },
    { label: '本年新政策个人缴费', prop: 'grzh21', type: 'input' },
    { label: '本年新政策单位代缴', prop: 'grzh23', type: 'input' },
    { label: '本年新政策单位缴费', prop: 'grzh22', type: 'input' },
    { label: '历年新政策单位缴费', prop: 'grzh25', type: 'input' },
    { label: '历年新政策个人缴费', prop: 'grzh24', type: 'input' },
    { label: '历年新政策单位代缴', prop: 'grzh26', type: 'input' },
    { label: '新政策缴费月数', prop: 'grzh27', type: 'input' }
  ]
});
const { dataForm } = toRefs(state);
const isVisible = ref(false);
watch(
  () => props.modelValue,
  async (v) => {
    isVisible.value = v;
    if (props.currentRow.id && v) {
      var res = await getAb05(props.currentRow.id);
      Object.keys(dataForm.value).forEach((item) => {
        dataForm.value[item] = res.data[item];
      });
    }
  },
  { immediate: true, deep: true }
);
const emit = defineEmits(['update:modelValue']);
const closed = () => {
  emit('update:modelValue');
};
/** 表单重置 */
const reset = () => {
  ruleForm.value?.resetFields();
};
</script>
